home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Imágenes y mapas de bits / DrawOnImage / DrawOnImage.cs next >
Encoding:
Text File  |  2002-05-06  |  1.2 KB  |  41 lines

  1. //------------------------------------------
  2. // DrawOnImage.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class DrawOnImage: PrintableForm
  9. {
  10.      Image  image;
  11.      string str = "Apollo11";
  12.  
  13.      public new static void Main()
  14.      {
  15.           Application.Run(new DrawOnImage());
  16.      }
  17.      public DrawOnImage()
  18.      {
  19.           Text  = "Dibujar sobre una imagen";
  20.           image = Image.FromFile("..\\..\\..\\Apollo11FullColor.jpg");
  21.  
  22.           Graphics grfxImage = Graphics.FromImage(image);
  23.  
  24.           grfxImage.PageUnit = GraphicsUnit.Inch;
  25.           grfxImage.PageScale = 1;
  26.  
  27.           SizeF sizef = grfxImage.MeasureString(str, Font);
  28.  
  29.           grfxImage.DrawString(str, Font, Brushes.White, 
  30.                          grfxImage.VisibleClipBounds.Width - sizef.Width, 0);
  31.  
  32.           grfxImage.Dispose();
  33.      }
  34.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  35.      {
  36.           grfx.PageUnit = GraphicsUnit.Pixel;
  37.           grfx.DrawImage(image, 0, 0);
  38.           grfx.DrawString(str, Font, new SolidBrush(clr),
  39.                     grfx.DpiX * image.Width / image.HorizontalResolution, 0);
  40.      }
  41. }